﻿using System;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

[RequireComponent(typeof(Slider))]
public class UIVolumeSlider : MonoBehaviour, IEventSystemHandler, IDragHandler, IPointerDownHandler, IPointerUpHandler
{
    public AudioSource testAudio;
    public Type type;

    private void Awake()
    {
        <Awake>c__AnonStorey77 storey = new <Awake>c__AnonStorey77 {
            <>f__this = this,
            slider = base.GetComponent<Slider>()
        };
        storey.slider.value = (this.type != Type.Sound) ? Singleton<AudioManager>.Instance.musicVolume : Singleton<AudioManager>.Instance.soundVolume;
        storey.slider.onValueChanged.AddListener(new UnityAction<float>(storey.<>m__13A));
    }

    public void OnDrag(PointerEventData eventData)
    {
        if ((this.testAudio != null) && !this.testAudio.isPlaying)
        {
            this.testAudio.Play();
        }
    }

    public void OnPointerDown(PointerEventData data)
    {
        if ((this.testAudio != null) && !this.testAudio.isPlaying)
        {
            this.testAudio.Play();
        }
    }

    public void OnPointerUp(PointerEventData data)
    {
        if (this.testAudio != null)
        {
            this.testAudio.Stop();
        }
    }

    [CompilerGenerated]
    private sealed class <Awake>c__AnonStorey77
    {
        internal UIVolumeSlider <>f__this;
        internal Slider slider;

        internal void <>m__13A(float v)
        {
            if (this.slider.normalizedValue == 0f)
            {
                v = -80f;
            }
            if (this.<>f__this.type == UIVolumeSlider.Type.Sound)
            {
                Singleton<AudioManager>.Instance.soundVolume = v;
            }
            if (this.<>f__this.type == UIVolumeSlider.Type.Music)
            {
                Singleton<AudioManager>.Instance.musicVolume = v;
            }
        }
    }

    public enum Type
    {
        Sound,
        Music
    }
}

